package com.sghd.candy.module.charge.manager;

import com.sghd.common.ramcache.IEntity;
import org.hibernate.annotations.Index;

import javax.persistence.*;
import java.util.Date;

/**
 * 充值记录实体
 */
@Entity
@NamedQueries({
        @NamedQuery(name = ChargeLog.MAX_ID, query = "select max(l.id) from ChargeLog as l where l.id between ? and ?"),
        @NamedQuery(name = ChargeLog.ORDER_ID, query = "from ChargeLog l where l.orderId = ?")
})
@Table(catalog = "bsdld")
@org.hibernate.annotations.Table(appliesTo = "ChargeLog", indexes = @Index(name = "IDX_CHARGELOG_TARGET", columnNames = "target"))
public class ChargeLog implements IEntity<Long> {
    /**id生成器使用*/
    public static final String MAX_ID = "ChargeLog.maxId";
    public static final String ORDER_ID = "ChargeLog.orderId";
    /** 标识 */
    @Id
    private Long id;
    /** 充值目标*/
    private long target;
    /** 充值订单号 */
    private long orderId;
    /** 充值获得的奖励*/
    private String reward;
    /** 充值花费金额 */
    private int money;
    /** 最近登陆IP */
    private String ip;
    /** 是否是第一次充值*/
    private boolean first;
    /** 创建时间*/
    private Date createdAt;

    /** 构造方法 */
    public static ChargeLog valueOf(long id, long target, long orderId, String reward, int money, String ip, boolean first) {
        ChargeLog result = new ChargeLog();
        result.id = id;
        result.target = target;
        result.orderId = orderId;
        result.reward = reward;
        result.money = money;
        result.createdAt = new Date();
        result.ip = ip;
        result.first = first;
        return result;
    }

    // Getter and Setter ...

    @Override
    public Long getId() {
        return id;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    void setId(Long id) {
        this.id = id;
    }

    public long getTarget() {
        return target;
    }

    void setTarget(long target) {
        this.target = target;
    }

    public long getOrderId() {
        return orderId;
    }

    void setOrderId(long order) {
        this.orderId = order;
    }

    public int getMoney() {
        return money;
    }

    void setMoney(int money) {
        this.money = money;
    }

    void setIp(String ip) {
        this.ip = ip;
    }

    public String getIp() {
        return ip;
    }

    public boolean isFirst() {
        return first;
    }

    void setFirst(boolean first) {
        this.first = first;
    }

    public String getReward() {
        return reward;
    }

    void setReward(String reward) {
        this.reward = reward;
    }
}
